package com.zs.leymovie.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.zs.leymovie.R;

import java.util.List;

/**
 * Created by Administrator on 2015/8/20.
 */
public class RecyAdapter extends RecyclerView.Adapter<RecyAdapter.ViewHolder> {
    private List<String> lists;
    private Context context;
    private static RecyViewOnClickListener  listener;
    public RecyAdapter ( List<String> lists, Context context){
        this.lists = lists;
        this.context = context;
    }
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.recyview_item,parent,false);
        ViewHolder vh = new ViewHolder(view);
        return vh;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
                holder.textView.setText(lists.get(position));
    }

    @Override
    public int getItemCount() {
        return lists == null ?0:lists.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
        @ViewInject(R.id.recy_text)
        public TextView textView;
        public ViewHolder(View itemView) {
            super(itemView);
            ViewUtils.inject(this,itemView);
            itemView.setOnClickListener(this);
        }

        @Override
        public void onClick(View v) {
             if(listener !=null){
                 listener.recyViewItemClick(v,getPosition());
             }
        }
    }
    public void setOnRecyViewOnClickListener(RecyViewOnClickListener listene){
         listener = listene;
    }

    public interface RecyViewOnClickListener{
        void recyViewItemClick(View v,int position);
    }
}
